#ifndef THERMOSTAT_H
#define THERMOSTAT_H

#include <Metro/Metro.h>
#include <Observer/Observer.h>
#include <Observer/Observable.h>

#define RELAY_PIN 12
#define LED_PIN 13

#define ON 1
#define OFF 0

#define TARGET_TEMP_ADDR 0
#define TEMP_RANGE_ADDR 8

#define MAX_TARGET_TEMP 100.0
#define MIN_TARGET_TEMP 0.0
#define DEFAULT_TARGET_TEMP 50.0
#define MAX_TEMP_RANGE 10.0
#define MIN_TEMP_RANGE 0.5
#define DEFAULT_TEMP_RANGE 1.0

#define MIN_OFF_TIME (ONE_MINUTE * 5)
#define MAX_ON_TIME  ONE_HOUR

class Thermostat : public Observer, public Observable {
  public:
    Thermostat(Metro *tempSampleTimer, Metro *relayEventTimer);
    void setTargetTemp(float targetTemp);
    float getTargetTemp() const;
    void setTempRange(float tempRange);
    float getTempRange() const;
    float getTempError() const;
    void setRelay(int relay);
    int getRelay() const;
    float getCurrentTemp() const;
    void update(Observable *o);
  private:
    float currentTemp;
    float targetTemp;
    float tempRange;
    int relay;
    Metro *tempSampleTimer;
    Metro *relayEventTimer;
    float readTemp();
};
    
#endif
